<?php

//include("config.php");
/*
$dbname='em_bd.sqlite';

$base=new SQLite3($dbname, 0666); 
*/


session_start();
include_once 'conectar_bd.php';
$base=  conectar_solo_lectura();

if($_SERVER["REQUEST_METHOD"] == "POST"){
    // username and password sent from form 

    $usr=addslashes($_POST['usuario']); 
    $pass=addslashes($_POST['password']); 
    //echo $usr;

    $sql="SELECT usuario, password FROM admin_user WHERE usuario='$usr'";
    $results = $base->query($sql);
    $row=$results->fetchArray();
    //echo sqlite_num_fields($results);
    
    //echo count($row);
    if(sizeof($row)==1){
        echo "el usuario no existe";
    }else{
        
        $pass_tabla=$row['password'];

        //$count=mysql_num_rows($result);


        // If result matched $myusername and $mypassword, table row must be 1 row
        if(sha1($pass)==$pass_tabla)
        {
            //session_register($usr);
            //$_SESSION['usuario'] = $usr;
            $_SESSION['login_user']=$usr;

            //header("location: admin.php");
            echo "logueado";
        }
        else 
        {
            echo "password inválido";
        //header("location: index.php");
        }
    }
}
?>